package com.fullstack.landscape.editor.service;

import com.fullstack.landscape.editor.common.ConfigKeyConstant;
import com.fullstack.landscape.editor.dao.mapper.ConfigMapper;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author leven.chen
 * @project landscape-editor
 * @date 2019/4/9 20:33
 * @apiNote
 */
@Component
public class ConfigService {

    @Autowired
    private ConfigMapper configMapper;

    public String getWorkspace() {
        Optional<String> config = configMapper.getConfig(ConfigKeyConstant.CKEY_WORKSPACE);
        String userHome = FileUtils.getUserDirectoryPath();

        return config.orElse(userHome + "/data/workspace");
    }
}
